<template>
  <div class="login-page">
    <!-- 背景装饰 -->
    <div class="bg-decoration"></div>

    <!-- 登录容器 -->
    <div class="login-container">
      <!-- 左侧品牌区域 -->
      <div class="brand-section">
        <h1 class="system-title">企业门户系统</h1>
      </div>

      <!-- 右侧登录区域 -->
      <div class="login-section">
        <h2 class="login-title">账号登录</h2>

        <el-form
            ref="form"
            :model="form"
            :rules="rules"
            class="login-form"
        >
          <el-form-item prop="username">
            <el-input
                v-model="form.username"
                placeholder="输入账号"
                prefix-icon="el-icon-user"
                :disabled="loading"
                class="login-input"
            ></el-input>
          </el-form-item>

          <el-form-item prop="password">
            <el-input
                v-model="form.password"
                type="password"
                placeholder="输入密码"
                prefix-icon="el-icon-lock"
                :disabled="loading"
                class="login-input"
            ></el-input>
          </el-form-item>

          <el-form-item class="login-button-group">
            <el-button
                type="primary"
                @click="onLogin"
                :loading="loading"
                class="login-btn"
            >
              登录
            </el-button>
          </el-form-item>

          <!-- 辅助功能链接 -->
          <div class="login-links">
            <el-link @click="handleForgotPassword" class="link-item">忘记密码</el-link>
            <el-link @click="handleRegister" class="link-item">用户注册</el-link>
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
//导入api
import {login} from '@/api/user'
export default {
  name: 'LoginView',
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      rules: {
        username: [
          {required: true, message: '请输入账号', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ]
      },
      loading: false
    };
  },
  methods: {
    onLogin() {
      console.log('发生登录前信息', this.form)
      //发请求
      login(this.form).then(res => {
        console.log('登录返回信息', res)
        if (res.code !== 200){
          this.$message.error('用户名或密码错误');
        }else {
          this.$message.success('登录成功');
          //向vuex存储登录信息
          this.$store.commit('setUserInfo',res.data)
          //跳转页面
          this.$router.push('/admin');
        }
      })
  },
  handleForgotPassword() {
    this.$message.info('跳转到忘记密码页面');
    // 实际项目中这里会跳转到忘记密码页面
  },
  handleRegister() {
    this.$message.info('跳转到用户注册页面');
    // 实际项目中这里会跳转到注册页面
  }
}
};
</script>

<style scoped>
.login-page {
  width: 100vw;
  height: 100vh;
  position: relative;
  overflow: hidden;
}

/* 背景装饰 */
.bg-decoration {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #e6f7f0 0%, #c3e6d6 100%);
  z-index: 1;
}

.bg-decoration::before,
.bg-decoration::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  filter: blur(80px);
}

.bg-decoration::before {
  width: 600px;
  height: 600px;
  top: -200px;
  right: 10%;
}

.bg-decoration::after {
  width: 400px;
  height: 400px;
  bottom: -100px;
  left: 15%;
}

/* 登录容器 */
.login-container {
  position: relative;
  z-index: 2;
  width: 900px;
  height: 500px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(10px);
  display: flex;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
}

/* 左侧品牌区域 */
.brand-section {
  width: 45%;
  padding: 60px 40px;
  background: linear-gradient(180deg, #2aa673 0%, #1d8b5c 100%);
  color: white;
  position: relative;
}

.system-title {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: 40px;
  position: relative;
  z-index: 2;
}
/* 右侧登录区域 */
.login-section {
  width: 55%;
  padding: 60px 50px;
  display: flex;
  flex-direction: column;
}

.login-title {
  font-size: 24px;
  color: #1d8b5c;
  margin-bottom: 40px;
  font-weight: 600;
  text-align: center;
}

.login-form {
  width: 100%;
  max-width: 300px;
  margin: 0 auto;
}

.login-input {
  height: 44px;
  border-radius: 6px;
  border-color: #d9d9d9;
  margin-bottom: 20px;
}

.login-input:focus {
  border-color: #2aa673 !important;
  box-shadow: 0 0 0 2px rgba(42, 166, 115, 0.2) !important;
}

.login-btn {
  width: 100%;
  height: 44px;
  font-size: 16px;
  background-color: #2aa673;
  border-color: #2aa673;
  border-radius: 6px;
}

.login-btn:hover, .login-btn:focus {
  background-color: #1d8b5c;
  border-color: #1d8b5c;
}

.login-links {
  display: flex;
  justify-content: space-between;
  margin-top: 20px;
}

.link-item {
  color: #666;
  font-size: 14px;
}

.link-item:hover {
  color: #2aa673;
}
</style>
